#include <stdio.h>
#include "../sjjg/bitmap.h"


void showMap(ms_bitmap b) {
    size_t size = ms_bitmap_size(b);
    for (size_t i = 0;i < MS_BITMAP_ALLOCSIZE(size);++i) {
        printf("%02x ", b->first[i]);
    }
    printf("\nsize:%lu\n", size);
}
int getSel() {
    printf("1.set\n");
    printf("2.get\n");
    printf("3.resize\n");
    printf("4.make\n");
    printf("5.show map\n");
    printf("6.delete\n");
    printf("7.clear\n");
    printf("other exit\n");
    printf("select please:");
    int i;
    scanf("%d", &i);
    return i;
}
size_t getV() {
    size_t a = rand() % 1000;
    printf("push a value:%lu\n", a);
    return a;
}

size_t getWhere(const char* str) {
    unsigned long i = 0;
    printf(str);
    scanf("%lu", &i);
    return i;
}

int main(int args, char* argv[]) {

    ms_bitmap b = ms_bitmap_create(NULL, 1024);
    if (b) {
        do
        {
            size_t w = 0;
            size_t a = 0;
            int sel = getSel();
            switch (sel) {
            case 1:
                a = getV();
                ms_bitmap_set(b, a);
                printf("%lu %02x\n", a/8, b->first[a/8]);
                break;
            case 2:
                a = getWhere("enter a pos:");
                printf("%d %02x\n", ms_bitmap_get(b, a), b->first[a/8]);
                break;
            case 3:
                w = getWhere("enter a size:");
                ms_bitmap_resize(b, w);
                break;
            case 4:
                w = ms_bitmap_make(b);
                printf("%lu %02x\n", w, b->first[w/8]);
                break;
            case 5:
                showMap(b);
                break;
            case 6:
                w = getWhere("enter a pos:");
                printf("old:%02x\n", b->first[w/8]);
                ms_bitmap_remove(b, w);
                printf("new:%02x\n", b->first[w/8]);
                break;
            case 7:
                ms_bitmap_clear(b);
                break;
            default:
                goto exit;
            }
        } while (1);
exit:
        ms_bitmap_destory(b);
    }
    return 0;
}
